<template>
	<view>
		<uni-popup ref="shop" type="bottom">
			<view style="height: 100%;height: 100vh;" class="flex flex-y flex-x-y" @click="close">

				<template v-if="shop_code">
					<image @tap.stop="preview_image()" :src="shop_code" style="width: 336rpx;height: 336rpx;margin-top: 30rpx;border-radius: 16rpx;"></image>
					<view @tap.stop="save_code" class="fs-28 save-1">保存到相册</view>
				</template>
				<qq-loading v-if="!shop_code" :show="true"></qq-loading>


			</view>
		</uni-popup>
	</view>
</template>

<script>
	let {download} = require('../../utils/util.js');
	export default {
		name: "shopcode",
		data() {
			return {
				shop_code: '',
			};
		},
		methods: {
			get_shop_code() {
				this.request({
					url: '/myShop/getQrcode',

				}).then(res => {
					if (!this.rsuccess(res, true)) return;
					this.shop_code = res.data;
					uni.setStorage({
						key: 'shop_code',
						data: res.data,
					})
				});
			},
			close() {
				this.$refs.shop.close();
			},
			open() {
				this.shop_code = uni.getStorageSync('shop_code') || '';
				this.$refs.shop.open();
				this.get_shop_code();
			},
			save_code(){
				download(this.shop_code);
			},
			preview_image(){
				uni.previewImage({
					urls:[this.shop_code]
				})
			},
		}
	}
</script>

<style>
	.save-1 {
		width: 300rpx;
		height: 88rpx;
		background-color: #A0E8E2;
		border-radius: 16rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 60rpx;
		color: #333333;
	}
</style>
